KERNEL_MAJOR 		= 0
KERNEL_PATCH_LEVEL 	= 0
KERNEL_SUBVER 		= 1

# initial the arch variables

HOSTARCH 		= $(shell uname -m)
HOSTCC 			= $(CC)


ifeq 	($(ARCH), )
	ARCH 		= $(HOSTARCH)

endif

PWD 			= $(shell pwd)
ARCHDIR 		= $(PWD)/arch/$(ARCH)

KERNEL_COMPILE_BY 	= $(shell whoami)
KERNEL_COMPILE_TIME 	= $(shell date)

KERNEL_VERSION 		= $(KERNEL_MAJOR).$(KERNEL_PATCH_LEVEL).$(KERNEL_SUBVER)\
			$(KERNEL_COMPILE_TIME) $(KERNEL_COMPILE_BY) on $(ARCH)

MAKEFLAGS		+= --no-print-directory 
CFLAGS 			+= -I$(PWD)/include/ -g -nostdinc -nostdlib -Wall -Werror 
ARCHCFLAGS 		+= $(shell cat $(ARCHDIR)/.archcflags)

SHELl 			= $(shell echo $$SHELL)

TARGET 			= vmevx.bin 


ifeq 	($(CROSS_COMPILE), )
	CROSS_COMPILE	= $(CC)
endif

ifeq 	($(CROSS_LD), )
	CROSS_LD 	= $(LD)
endif


ifeq 	($(ARCH), x86_64) 
	ARCH		= x86
endif


ifeq 	($D,)


# that inside object, and we don't support other objects at this time :-)

obj-i 			+= $(ARCHDIR)/ 
obj-i 			+= $(ARCHDIR)/kernel/ 
obj-i 			+= $(PWD)/init/ 
obj-i 			+= $(PWD)/kernel/ 
obj-i 			+= $(PWD)/modules/ 
obj-i 			+= $(PWD)/lib/ 



_all: include/config.h 
	@rm .objlist -f 

	@for d in $(obj-i); do 				\
		$(MAKE) -C $$d D=$$d $(MAKEFLAGS); 	\
	done

	@$(MAKE) -C $(ARCHDIR)/ vmevx.o
	@$(MAKE) -C $(ARCHDIR)/ boot 


include/config.h: 
	@scripts/do_mkconfig.py 



.PHONY clean:
	@find ./ -name "*.o" \
	       -o -name "*.bin"	| xargs rm -f
	@$(MAKE) -C $(ARCHDIR)/ clean


else

__all: 	
	@for d in $(obj-i); do 										\
		$(SHELL) scripts/do_build.sh $$d $(CROSS_COMPILE) $D "$(CFLAGS)" "$(ARCHCFLAGS)";	\
		echo $D/$$d.o >> .objlist;								\
	done

endif

